<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}">
    <script th:src="@{/webjars/jquery/1.11.1/jquery.js}"></script>
    <script th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.js}"></script>
</head>
<body>
<div class="container">
    <p th:if="${session.loginUser!=null}">欢迎你,
        <b th:text="|${session.loginUser.nickName}(${session.loginUser.username})${session.loginUser.role.name}|"></b>
        <a title="注销登陆" th:href="@{/logout}" class="btn btn-link">登出</a>
    </p>
    <p th:unless="${session.loginUser!=null}">
        <a class="btn btn-link" th:href="@{/login}">去登录</a>
    </p>

    <h1>图书列表</h1>
    <div class="text-right" th:if="${session.loginUser!=null and session.loginUser.role.name eq '管理员'}">
        <a class="btn btn-default" th:href="@{/book/list_vue}">VUE-MODEL<span class="glyphicon glyphicon-plus"></span></a>

        <a class="btn btn-default" th:href="@{/book/add}">添加图书<span class="glyphicon glyphicon-plus"></span></a>
        <a class="btn btn-primary" th:href="@{/discount/list}">查看折扣规则</a>
    </div>
    <div>
        <form class="form-inline" th:action="@{/book/list}">
            <label>书名</label>
            <input class="form-control" type="text" name="name" placeholder="请输入关键字快速查找图书" th:value="${bookName}">
            <label>图书类别</label>
            <select class="form-control" type="text" name="category.id">
                <option value="0" th:text="全类别"></option>
                <option th:each="category:${categories}" th:value="${category.id}" th:text="${category.name}"
                th:selected="${categoryId==category.id}"></option>
            </select>
            <button class="btn btn-default">查找<span class="glyphicon glyphicon-search"></span></button>
        </form>
    </div>
    <table class="table table-striped table-hover">
        <thead>
        <tr>
            <th>序号</th>
            <th>书名</th>
            <th>作者</th>
            <th>类别</th>
            <th>库存</th>
            <th>定价</th>
            <th>促销价</th>
            <th>会员价</th>
        </tr>
        </thead>
        <tbody>
        <!--                使用themeleaf完成数据渲染-->
        <tr th:each="book:${bookList}" th:object="${book}">
            <td th:text="*{id}"></td>
            <td th:text="*{name}"></td>
            <td th:text="*{author}"></td>
            <td th:text="*{category.name}"></td>
            <td th:text="*{repository}"></td>
            <td th:text="*{price}"></td>
            <td th:text="*{promotionPrice==null}?'--':*{promotionPrice}"></td>
            <td th:text="*{VipPrice==null}?'--':*{VipPrice}"></td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>